import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/buttons/floatingActionButtonAddBooksToFolder.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerIndividual.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/module/openLibraryReadingBody.dart';
import 'package:ichinesereader/widgets/sidebars/individualSidebar.dart';
import '../../controller/books.dart';
import '../../models/common/LevelOption.dart';

class IndividualOpenLibraryScreen extends StatelessWidget {
  final box = Hive.box('appconfig');
  static const String routeName = '/individual/library';

  @override
  Widget build(BuildContext context) {
    Log.debug('build IndividualBookLibraryScreen');
    bool isIndividual = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Individual;
    List<LevelOption> levelOptions = [];
    final BooksController _booksController = Get.find();
    _booksController.setLevelOptions(levelOptions);
    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.individualPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    return Scaffold(
      appBar: isSmallScreen ? CustomAppBar(title: 'Library'.tr) : null,
      drawer: isSmallScreen ? IndividualAppDrawer() : null,
      body: Container(
        decoration: _pageStyles.pageBoxDecoration(),
        child: Row(
          children: [
            Visibility(
                visible: !isSmallScreen,
                child: Container(
                    child: IndividualSidebarX(
                        selectedIndex: _selectedSidebarItem,
                        isBigScreen: isBigScreen))),
            Expanded(
              child: Container(
                margin: _pageStyles.mainContainerWithPaginationEdgeInsets(),
                child: isIndividual ? OpenLibraryReadingBody() : Text(''),
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButtonAddBookToFolder(
        readingType: NanhaiBookReadingTypes.library,
      ),
    );
  }
}
